home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Source Code
/
Pascal
/
Snippets
/
PNL Libraries
/
MyVBLSync.p
< prev
next >
Wrap
Text File
|
1997-05-07
|
2KB
|
105 lines
unit MyVBLSync;
interface
var
vbl_count: longint;
procedure StartupVBLSync;
procedure SetVBLSyncing( on: boolean );
function IsVBLSyncing: boolean;
procedure WaitForSync;
implementation
uses
Types, LowMem, Menus, Timer, Windows, Retrace, Devices, Quickdraw, OSUtils, MixedMode,
GammaPaslib,
MyStartup, MyAssertions, MyWindows, MyLowLevel,
PreserveA5;
var
syncing: boolean;
task: VBLTask;
vbl_proc: VBLUPP;
procedure RealVBLTask( task: VBLTaskPtr );
begin
Inc(vbl_count);
task^.vblCount := 1;
end;
{$ifc GENERATINGCFM}
procedure VBLTask( task: VBLTaskPtr );
begin
RealVBLTask( task );
end;
{$elsec}
procedure VBLTask;
begin
RealVBLTask( VBLTaskPtr(GetRegA0) );
end;
{$endc}
procedure SetVBLSyncing( on: boolean );
var
mainDCE: AuxDCEHandle;
err: OSErr;
begin
if syncing <> on then begin
mainDCE := AuxDCEHandle( GetDCtlEntry( GetMainDevice^^.gdRefNum ) );
if on then begin
task.vblAddr := vbl_proc;
task.qType := vType;
task.vblCount := 1;
err := SlotVInstall( @task, mainDCE^^.dCtlSlot );
if err = noErr then begin
syncing := true;
end;
end else begin
err := SlotVRemove( @task, mainDCE^^.dCtlSlot );
Inc(vbl_count);
syncing := false;
end;
end;
end;
function IsVBLSyncing: boolean;
begin
IsVBLSyncing := syncing;
end;
procedure WaitForSync;
var
old_count: longint;
begin
old_count := vbl_count;
while syncing and (vbl_count = old_count) do begin
end;
end;
function InitVBLSync( var msg: integer ): OSStatus;
begin
{$unused(msg)}
syncing := false;
vbl_count := 0;
vbl_proc := NewVBLProc( @VBLTask );
InitVBLSync := noErr;
end;
procedure FinishVBLSync;
begin
SetVBLSyncing( false );
DisposeRoutineDescriptor( vbl_proc );
end;
procedure StartupVBLSync;
begin
StartupPreserveA5;
SetStartup( InitVBLSync, nil, 0, FinishVBLSync );
end;
end.